package com.mmy.frame.base.view

import android.app.Activity
import android.os.Bundle
import android.support.v4.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.mmy.frame.AppComponent
import com.mmy.frame.FrameApp
import com.mmy.frame.base.mvp.IPresenter
import com.mmy.frame.base.mvp.IView
import com.mmy.frame.helper.CommentHelper
import javax.inject.Inject


/**
 * @创建者     lucas
 * @创建时间   2017/12/25 0025 15:20
 * @描述          TODO
 */
open abstract class BaseFragment< P : IPresenter<*>> : Fragment(), IView ,CommentHelper{

    @Inject lateinit var mIPresenter: P

    override fun onCreateView(inflater: LayoutInflater?, container: ViewGroup?, savedInstanceState: Bundle?): View {
        setupDagger((activity.application as FrameApp).appComponent)
        val inflate = LayoutInflater.from(activity).inflate(getLayoutId(), null, false)
        initView()
        initData()
        initEvent()
        return inflate
    }

    abstract fun setupDagger(appComponent: AppComponent)
    abstract fun getLayoutId(): Int
    abstract fun initView()
    abstract fun initData()
    abstract fun initEvent()


    override fun showLoading() {
        (activity as BaseActivity<*>).showLoading()
    }

    override fun hidLoading() {
        (activity as BaseActivity<*>).hidLoading()
    }

    override fun <A : Activity> openActivity(activity: Class<A>, params: String, isResult: Boolean, requestCode: Int) {
        (activity as BaseActivity<*>).openActivity(activity,params,isResult,requestCode)
    }
}